Skip to main content

Sending Files to and from Your Server via SSH

Prerequisites

  • SSH access to your server.
  • scp installed on your local machine (it comes pre-installed on most Unix-based systems).

Sending a File to Your Server

  1. Ensure you have SSH access to your server:

    ssh your_username@your_server_ip
  2. Use scp to send a file from your local machine to your server:

    scp /path/to/local/file your_username@your_server_ip:/path/to/remote/destination

    Example

    To send example.txt from your local ~/Documents directory to the /home/your_username directory on your server:

    scp ~/Documents/example.txt your_username@your_server_ip:/home/your_username/
  3. Enter your SSH password when prompted.

  4. Verify the file transfer by logging into your server and checking the destination directory:

    ssh your_username@your_server_ip
    ls /home/your_username/

Downloading a File from Your Server

  1. Ensure you have SSH access to your server:

    ssh your_username@your_server_ip
  2. Use scp to download a file from your server to your local machine:

    scp your_username@your_server_ip:/path/to/remote/file /path/to/local/destination

    Example

    To download example.txt from the /home/your_username directory on your server to your local ~/Downloads directory:

    scp your_username@your_server_ip:/home/your_username/example.txt ~/Downloads/
  3. Enter your SSH password when prompted.

  4. Verify the file transfer by checking the destination directory on your local machine:

    ls ~/Downloads/

Additional Tips

  • Uploading/Downloading a Directory:

    • Use the -r (recursive) option to upload/download entire directories.
      # Upload a directory
      scp -r /path/to/local/directory your_username@your_server_ip:/path/to/remote/destination

      # Download a directory
      scp -r your_username@your_server_ip:/path/to/remote/directory /path/to/local/destination
  • Specifying a Different SSH Port:

    • If your SSH server uses a different port, use the -P option.
      # Uploading with a specific port
      scp -P 2222 /path/to/local/file your_username@your_server_ip:/path/to/remote/destination

      # Downloading with a specific port
      scp -P 2222 your_username@your_server_ip:/path/to/remote/file /path/to/local/destination
  • Get your actual system location:

    • Run the pwd Command

      Simply type pwd and press Enter.

      pwd

      Example Output

      If you are in your home directory, the output might look something like this:

      /home/your_username

By following this tutorial, you can easily send files to and from your server via SSH using scp.